import {defineConfig} from 'vite' // 帮手函数，这样不用 jsdoc 注解也可以获取类型提示
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import {resolve} from "path"; // 主要用于alias文件路径别名
// const path = require('path')

// 构建打包版本别名
const now = new Date()
const version = now.toISOString().replace(/[-:.TZ]/g, '')

//新增别名
function pathResolve(dir) {
    return resolve(__dirname, dir);
}

export default defineConfig({
    // base: path.resolve(__dirname, './dist'),
    plugins: [vue(),vueJsx()],
    resolve: {
        alias: {
            "@": pathResolve("./src")
        }
    },
    optimizeDeps: {
        include: ['axios']
    },
    build: {
        target: 'modules',
        // outDir: `linshensjl.top_${version}_dist`,
        outDir: `dist`,
        assetsDir: 'assets',
        minify: 'terser', // 混淆器
        manifest: false,
        rollupOptions: {
            output: {
                entryFileNames: `assets/[name].js`,
                chunkFileNames: `assets/[name].js`,
                assetFileNames: `assets/[name].[ext]`,
            }
        },
        chunkSizeWarningLimit: 1600,
    },
    server: {
        proxy: {
            '/api': {
                target: 'http://localhost:3000/api',   //代理接口
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        },
        cors: true,
        open: false,
        port: 8888,
        compress: true,
        hot: true,
        liveReload: true,
        overlay: true
    }
});

